<?php

namespace App\Http\Controllers\API;

use App\Http\Requests\API\CreateGoodsSlideshowAPIRequest;
use App\Http\Requests\API\UpdateGoodsSlideshowAPIRequest;
use App\Models\GoodsSlideshow;
use App\Repositories\GoodsSlideshowRepository;
use Illuminate\Http\Request;
use App\Http\Controllers\AppBaseController;
use InfyOm\Generator\Criteria\LimitOffsetCriteria;
use Prettus\Repository\Criteria\RequestCriteria;
use Response;

/**
 * Class GoodsSlideshowController
 * @package App\Http\Controllers\API
 */

class GoodsSlideshowAPIController extends AppBaseController
{
    /** @var  GoodsSlideshowRepository */
    private $goodsSlideshowRepository;

    public function __construct(GoodsSlideshowRepository $goodsSlideshowRepo)
    {
        $this->goodsSlideshowRepository = $goodsSlideshowRepo;
    }

    /**
     * Display a listing of the GoodsSlideshow.
     * GET|HEAD /goodsSlideshows
     *
     * @param Request $request
     * @return Response
     */
    public function index(Request $request)
    {
        $this->goodsSlideshowRepository->pushCriteria(new RequestCriteria($request));
        $this->goodsSlideshowRepository->pushCriteria(new LimitOffsetCriteria($request));
        $goodsSlideshows = $this->goodsSlideshowRepository->all();

        return $this->sendResponse($goodsSlideshows->toArray(), 'Goods Slideshows retrieved successfully');
    }

    /**
     * Store a newly created GoodsSlideshow in storage.
     * POST /goodsSlideshows
     *
     * @param CreateGoodsSlideshowAPIRequest $request
     *
     * @return Response
     */
    public function store(CreateGoodsSlideshowAPIRequest $request)
    {
        $input = $request->all();

        $goodsSlideshows = $this->goodsSlideshowRepository->create($input);

        return $this->sendResponse($goodsSlideshows->toArray(), 'Goods Slideshow saved successfully');
    }

    /**
     * Display the specified GoodsSlideshow.
     * GET|HEAD /goodsSlideshows/{id}
     *
     * @param  int $id
     *
     * @return Response
     */
    public function show($id)
    {
        /** @var GoodsSlideshow $goodsSlideshow */
        $goodsSlideshow = $this->goodsSlideshowRepository->findWithoutFail($id);

        if (empty($goodsSlideshow)) {
            return $this->sendError('Goods Slideshow not found');
        }

        return $this->sendResponse($goodsSlideshow->toArray(), 'Goods Slideshow retrieved successfully');
    }

    /**
     * Update the specified GoodsSlideshow in storage.
     * PUT/PATCH /goodsSlideshows/{id}
     *
     * @param  int $id
     * @param UpdateGoodsSlideshowAPIRequest $request
     *
     * @return Response
     */
    public function update($id, UpdateGoodsSlideshowAPIRequest $request)
    {
        $input = $request->all();

        /** @var GoodsSlideshow $goodsSlideshow */
        $goodsSlideshow = $this->goodsSlideshowRepository->findWithoutFail($id);

        if (empty($goodsSlideshow)) {
            return $this->sendError('Goods Slideshow not found');
        }

        $goodsSlideshow = $this->goodsSlideshowRepository->update($input, $id);

        return $this->sendResponse($goodsSlideshow->toArray(), 'GoodsSlideshow updated successfully');
    }

    /**
     * Remove the specified GoodsSlideshow from storage.
     * DELETE /goodsSlideshows/{id}
     *
     * @param  int $id
     *
     * @return Response
     */
    public function destroy($id)
    {
        /** @var GoodsSlideshow $goodsSlideshow */
        $goodsSlideshow = $this->goodsSlideshowRepository->findWithoutFail($id);

        if (empty($goodsSlideshow)) {
            return $this->sendError('Goods Slideshow not found');
        }

        $goodsSlideshow->delete();

        return $this->sendResponse($id, 'Goods Slideshow deleted successfully');
    }
}
